package com.tlias.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.tlias.mapper.EmpMapper;
import com.tlias.pojo.Emp;
import com.tlias.pojo.PageBean;
import com.tlias.pojo.Result;
import com.tlias.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;


//    @Override
//    public PageBean page(Integer page, Integer pageSize) {
//        PageHelper.startPage(page, pageSize);
//        empMapper.list<Emp> empList = empMapper.list(name, gender, begin, end);
//        Page<Emp> page1 = (Page<Emp>) empList;
//        PageBean pageBean=new PageBean(page1.getTotal(),page1.getResult());
//
//        return pageBean;
//    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {
        PageHelper.startPage(page, pageSize);
        List<Emp> empList = empMapper.list(name, gender, begin, end);
        Page<Emp> p = (Page<Emp>) empList;
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    //删除
    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
//添加

    public void addEmp(Emp emp) {

        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.addEmp(emp);
    }

    //更改
    @Override
    public void updateEmp(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.updateEmp(emp);
    }

    //id查询
    @Override
    public Emp findEmp(Integer id) {


        return empMapper.findEmp(id);
    }
//
//    @Override
//    public PageBean page(Integer page, Integer pageSize) {
//        Long count = empMapper.count();
//        Integer start=(page-1)*pageSize;
//
//        List<Emp> list = empMapper.list(start, pageSize);
//        PageBean pageBean=new PageBean(count,list);
//
//
//        return pageBean;
//    }
}




